package com.yueshang.neuron.modular.system.controller;

import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yueshang.common.entity.ResultResponse;
import com.yueshang.framework.constant.factory.PageFactory;
import com.yueshang.neuron.common.enums.BizLogEnum;
import com.yueshang.neuron.common.enums.ResultCodeEnum;
import com.yueshang.neuron.core.warpper.LogWarpper;
import com.yueshang.neuron.modular.system.api.IOperationLogService;
import com.yueshang.neuron.modular.system.model.OperationLog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 日志管理的控制器
 *
 * @author shililu
 * @Date 2018-08-30
 */
@Controller
@RequestMapping("/v1/operationlog")
public class OperationLogController extends ApiController {


    @Autowired
    private IOperationLogService operationLogService;


    /**
     * 查询操作日志列表
     */
    @RequestMapping("/logs")
    @ResponseBody
    public Object list(@RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String logName, @RequestParam(required = false) Integer logType) {
        Page<OperationLog> page = new PageFactory<OperationLog>().defaultPage();
        List<Map<String, Object>> result = operationLogService.getOperationLogs(page, beginTime, endTime, logName, BizLogEnum.valueOf(logType));
        page.setRecords((List<OperationLog>) new LogWarpper(result).warp());
        return ResultResponse.ok(ResultCodeEnum.GAIN_SUCCESS.getCode(), ResultCodeEnum.GAIN_SUCCESS.getMsg(), page);
    }
}
